package com.wan37.logic.guild.service.impl;

import com.wan37.logic.guild.dao.GuildDao;
import com.wan37.logic.guild.domain.entity.GuildDO;
import com.wan37.logic.guild.domain.vo.GuildVO;
import com.wan37.logic.guild.service.GuildService;
import com.wan37.logic.guild.service.GuildUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-08-04 10:39
 **/
@Service("guildService")
public class GuildServiceImpl implements GuildService {
    @Autowired
    private GuildDao guildDao;
    @Autowired
    private GuildUserService guildUserService;
    @Override
    public boolean update(GuildVO guildVO) {

        return guildDao.update(new GuildDO(guildVO));
    }

    @Override
    public boolean save(GuildVO guildVO) {
        return guildDao.add(new GuildDO(guildVO));
    }

    @Override
    public boolean delete(GuildVO guildVO) {
        return false;
    }

    @Override
    public List<GuildVO> getAll() {
        List<GuildDO> guildDOList = guildDao.getAll();
        List<GuildVO> guildVOList = null;
        if (guildDOList != null){
            guildVOList = new ArrayList<>();
            for (GuildDO guildDO : guildDOList){
                GuildVO guildVO = new GuildVO(guildDO);
                guildVOList.add(guildVO);
            }
        }
        return guildVOList;
    }

    @Override
    public boolean deleteByGuildId(String guildId) {
        guildDao.deleteByGuildId(guildId);
        guildUserService.deleteByGuildId(guildId);
        return true;
    }

    @Override
    public GuildVO getGuildByGuildId(String guildId) {
        List<GuildDO> guildDOList = guildDao.getGuildDOByGuildId(guildId);
        GuildVO guildVO = null;
        if (guildDOList != null){
            guildVO = new GuildVO(guildDOList.get(0));
        }
        return guildVO;
    }
}
